using System;
using System.Collections.Generic;
using System.Linq;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db.Hr;


namespace HengTong.ViewModel.Person.SysPersonSocialSecurityVms
{
    public partial class SysPersonSocialSecurityListVm : BaseListVm<SysPersonSocialSecurityView, SysPersonSocialSecuritySearcher>
    {

        protected override IEnumerable<IGridColumn<SysPersonSocialSecurityView>> InitGridHeader()
        {
            return new List<GridColumn<SysPersonSocialSecurityView>>{
                this.MakeGridHeader(x => x.PersonName),
                this.MakeGridHeader(x => x.SchemeName),
                this.MakeGridHeader(x => x.SocialSecurityNo),
                this.MakeGridHeader(x => x.HousingFundAccount),
                this.MakeGridHeader(x => x.EnrollmentDate),
                this.MakeGridHeader(x => x.Status),
                this.MakeGridHeader(x => x.PaymentMonth),
                this.MakeGridHeader(x => x.Remark),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysPersonSocialSecurityView> GetSearchQuery()
        {
            var query = DC.Set<SysPersonSocialSecurity>()
                .CheckEqual(Searcher.PersonId, x=>x.PersonId)
                .CheckEqual(Searcher.SchemeId, x=>x.SchemeId)
                .CheckContain(Searcher.SocialSecurityNo, x=>x.SocialSecurityNo)
                .CheckContain(Searcher.HousingFundAccount, x=>x.HousingFundAccount)
                .CheckBetween(Searcher.EnrollmentDate?.GetStartTime(), Searcher.EnrollmentDate?.GetEndTime(), x => x.EnrollmentDate, includeMax: false)
                .CheckEqual(Searcher.Status, x=>x.Status)
                .CheckContain(Searcher.PaymentMonth, x=>x.PaymentMonth)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .Select(x => new SysPersonSocialSecurityView
                {
				    ID = x.ID,
                    PersonName = x.Person.Name,
                    SchemeName = x.Scheme.SchemeName,
                    SocialSecurityNo = x.SocialSecurityNo,
                    HousingFundAccount = x.HousingFundAccount,
                    EnrollmentDate = x.EnrollmentDate,
                    Status = x.Status,
                    PaymentMonth = x.PaymentMonth,
                    Remark = x.Remark,
                })
                .OrderBy(x => x.ID);
            return query;
        }
    }

    public class SysPersonSocialSecurityView : SysPersonSocialSecurity{
        [Display(Name = "姓名")]
        public String PersonName { get; set; }
        [Display(Name = "方案名称")]
        public String SchemeName { get; set; }

    }
}
